home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / PRGMANIA / BFED.10 / SLIDER.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-16  |  7.5 KB  |  277 lines

  1. /*
  2.     file: slider.c
  3.     utility:
  4.     date: 1989
  5.     author: Jim Charlton
  6.     modifications:
  7.         1995: C. Moreau: 
  8.     comments: 
  9. */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12.  
  13. #ifdef __PUREC__ 
  14. #include <aes.h>
  15. #include <vdi.h>
  16. #include <compend.h>
  17. #else
  18. #include <aesbind.h>
  19. #include <vdibind.h>
  20. #endif
  21.  
  22. #include "init.h"
  23. #include "onepage.h"
  24. #include "send.h"
  25. #include "slider.h"
  26. #include "wind.h"
  27.  
  28. /*
  29.     locals functions
  30. */
  31. static void scroll(windowptr thewin,int upflag,int dnflag);
  32. static void size_vslider(int wihandle);
  33.  
  34. /*
  35.     name: vhandler
  36.     utility: takes care of displaying the correct text in the
  37.         window after the slider has been moved or the window
  38.         resized
  39.     comment: 
  40.     parameters:
  41.     return: none
  42.     date: 1989
  43.     author: Jim Charlton
  44.     modifications:
  45.         1995: C. Moreau: 
  46. */
  47. void vhandler(const int *message, const windowptr thewin)
  48. {
  49.     const int vslideold = thewin->vslidepos;  /* save the old slider position  */
  50.     int        vslide; 
  51.     const long winlines = thewin->work.g_h/gl_hchar; /* no of lines can put in window  */
  52.     const long totallines = 1 + thewin->flen/16;
  53.         /* calculate the line number (from the top of the file) for the top
  54.             line displayed on the screen when the last full page of text
  55.             is being displayed in the window    */
  56.     long topwlnmax = ((totallines - winlines)>0) ? (totallines-winlines) : 0;
  57.         /* topwline is the top line of the currently displayed page */
  58.      long topwline = (thewin->topchar/16 < topwlnmax) ? thewin->topchar/16 : topwlnmax;
  59.  
  60.     if (thewin->topchar > topwline*16)
  61.         send_redraw(thewin);
  62.  
  63.     thewin->topchar = topwline*16;
  64.  
  65.     if (topwlnmax)
  66.         thewin->vslidepos = (int)((1000*topwline)/topwlnmax);
  67.     else
  68.         thewin->vslidepos = 1;
  69.  
  70.     switch (message[0]) {
  71.         case WM_ARROWED    :        
  72.             switch (message[4]) {
  73.                 case WA_UPPAGE :     /* uppage */
  74.                     topwline = (topwline-winlines+1>0) ? topwline-winlines+1 : 0;
  75.                     thewin->topchar = topwline*16;
  76.                     if (topwline == 0)
  77.                         thewin->vslidepos = 1;
  78.                     else
  79.                         thewin->vslidepos = (int)((1000*topwline)/topwlnmax);
  80.                     send_redraw(thewin); 
  81.                     break;
  82.                 case WA_DNPAGE :      /* dnpage  */
  83.                     topwline += winlines - 1;
  84.                     if (topwline>topwlnmax)
  85.                         topwline = topwlnmax;
  86.                     thewin->topchar = topwline*16;
  87.                     if (!topwline)
  88.                         thewin->vslidepos = 1;
  89.                     else
  90.                         thewin->vslidepos = (int)((1000*topwline)/topwlnmax);
  91.                     send_redraw(thewin); 
  92.                     break;
  93.                 case WA_UPLINE :      /* upline  */  
  94.                     if (--topwline<0)
  95.                         topwline++;
  96.                     else
  97.                     {
  98.                         thewin->topchar = topwline*16;
  99.                         if(!topwline)
  100.                             thewin->vslidepos = 1;
  101.                          else
  102.                              thewin->vslidepos = (int)((1000*topwline)/topwlnmax);
  103.                         scroll(thewin,0,1);
  104.                         redraw_vslider(thewin);
  105.                     }  
  106.                     break;
  107.                 case WA_DNLINE :      /* dnline  */
  108.                     if (++topwline>topwlnmax)
  109.                         topwline--;
  110.                     else
  111.                      {
  112.                          thewin->topchar = topwline*16;
  113.                         if(!topwline)
  114.                             thewin->vslidepos = 1;
  115.                            else
  116.                                thewin->vslidepos = (int)((1000*topwline)/topwlnmax);
  117.                         scroll(thewin,1,0);
  118.                         redraw_vslider(thewin);
  119.                     }  
  120.                     break;         }  /* end of switch message[4]  */
  121.             break; /* from WM_ARROWED */
  122.                 
  123.     case WM_VSLID :
  124.               /* the sliderbox was "pulled" up or down  */
  125.         vslide = message[4];
  126.           /* if the slider box was moved by less than 5 units do nothing */
  127.         if (abs(vslideold-vslide) < 5) 
  128.         {
  129.             vslide = vslideold;
  130.         }
  131.         else
  132.         {
  133.             topwline = vslide*topwlnmax/1000;
  134.             thewin->topchar = topwline*16;
  135.              thewin->vslidepos = vslide;
  136.             send_redraw(thewin);
  137.         }    
  138.         
  139.         break; /* from WM_VSLID    */
  140.     }    /* end of switch message[0]  */
  141. }
  142.  
  143. /*
  144.     name: redraw_vslider
  145.     utility: redraws vslider in new postion  
  146.     comment: 
  147.     parameters: int wihandle: window handle
  148.                 windowptr thewin: ptr on window structure
  149.     return: none
  150.     date: 1989
  151.     author: Jim Charlton
  152.     modifications:
  153.         aug 96: C. Moreau: added windowptr parameter
  154. */
  155. void redraw_vslider(const windowptr thewin)
  156. {
  157.     int vslide_size, dummy;
  158.     long totallines, seenlines;
  159.     const int handle = thewin->handle;
  160.     
  161.     if (!thewin->form)
  162.     {
  163.         totallines = 1 + thewin->flen/16;
  164.         
  165.         seenlines = min(totallines, (thewin->work.g_h/gl_hchar));
  166.         vslide_size = (int)min(1000, 1000*seenlines/totallines);
  167.         
  168.       /* redraw the slider  to its new position and with new size */                
  169.         wind_update(BEG_UPDATE);            
  170.         wind_set(handle, WF_VSLSIZE, vslide_size, 0, 0, 0);
  171.         wind_set(handle, WF_VSLIDE, thewin->vslidepos,        \
  172.                 &dummy, &dummy, &dummy);        
  173.         wind_update(END_UPDATE);
  174.     }
  175. }
  176.  
  177. /*
  178.     name: size_vslider
  179.     utility: set slider size  and redraws it 
  180.     comment: 
  181.     parameters:
  182.     return: none
  183.     date: 1989
  184.     author: Jim Charlton
  185.     modifications:
  186. */
  187. static void size_vslider(int wihandle)
  188. {
  189.     windowptr thewin = findwindowptr(wihandle);
  190.     const long totallines = 1 + thewin->flen/16;
  191.     const long seenlines = min(totallines,(thewin->work.g_h/gl_hchar));
  192.     const int vslide_size = (int)min(1000,1000*seenlines/totallines);
  193.     
  194.     wind_set(wihandle, WF_VSLSIZE, vslide_size, 0, 0, 0);
  195. }
  196.  
  197. /*
  198.     name: scroll
  199.     utility: 
  200.     comment: the scroll routine which moves text up if the up flag
  201.         is set and down if the dnflag is set.  The other flag must
  202.         be zero. Finally blanks the space for the new line at top or
  203.         bottom and sets the clipping rectangle for just that line in
  204.         preparation for the text in the window to be redrawn. 
  205.         Be sure to reset the clipping to the full window work area
  206.         after redrawing the    text.          
  207.     parameters:
  208.     return: none
  209.     date: 1989
  210.     author: Jim Charlton
  211.     modifications:
  212.         1995: C. Moreau: 
  213. */
  214. static void scroll(windowptr thewin,int upflag,int dnflag)
  215. {
  216.     int pxyc[4];    /* pxy copy */
  217.     const int lines_onscrn=thewin->work.g_h/gl_hchar;
  218.  
  219.           /* upflag=1 dnflag=0 for scroll up one line  */
  220.           /* upflag=0 dnflag=1 for scroll down one line  */
  221.  
  222.     pxyarray[0] = thewin->work.g_x;
  223.     pxyarray[2] = thewin->work.g_x + thewin->work.g_w;
  224.     pxyarray[4] = thewin->work.g_x;
  225.     pxyarray[6] = thewin->work.g_x + thewin->work.g_w;
  226.  
  227.     if (upflag)
  228.     {
  229.         pxyarray[1] = thewin->work.g_y + gl_hchar;
  230.         pxyarray[3] = thewin->work.g_y + thewin->work.g_h - 1;
  231.         pxyarray[5] = thewin->work.g_y;
  232.         pxyarray[7] = thewin->work.g_y + thewin->work.g_h - 1 - gl_hchar;
  233.     }
  234.     
  235.     if (dnflag)
  236.     {    pxyarray[1] = thewin->work.g_y;
  237.         pxyarray[3] = thewin->work.g_y + thewin->work.g_h - 1 - gl_hchar;
  238.         pxyarray[5] = thewin->work.g_y + gl_hchar;
  239.         pxyarray[7] = thewin->work.g_y + thewin->work.g_h - 1;
  240.     } 
  241.         /* scroll window */
  242.         
  243.     vro_cpyfm(thewin->graf.handle, S_ONLY, pxyarray,
  244.                  &thewin->graf.mfdb, &thewin->graf.mfdb);
  245.       /* now blank the top or bottom line as appropriate  */
  246.     pxyc[0] = thewin->work.g_x;
  247.     pxyc[2] = thewin->work.g_x + thewin->work.g_w - 1;
  248.  
  249.  
  250.  /* if scroll up/dwn then blank out the
  251.                               last/first line on the screen  */
  252.     if (upflag)  
  253.     {
  254.         pxyc[1] = thewin->work.g_y + (lines_onscrn-1)*gl_hchar + 1;
  255.         pxyc[3] = thewin->work.g_y + thewin->work.g_h - 1;
  256.  /* set the clip rect to the line to be redrawn */ 
  257.         vs_clip(thewin->graf.handle,1,pxyc);
  258.         vr_recfl(thewin->graf.handle,pxyc);
  259.         graf_mouse(M_OFF, 0L);
  260.         one_line2(thewin,thewin->topchar+(thewin->work.g_h/gl_hchar)*16-8); 
  261.         graf_mouse(M_ON, 0L);
  262.  /* the pos passed to one_line2 is topchar+g_h/16*16    */
  263.     }
  264.     
  265.     if (dnflag)
  266.     {
  267.         pxyc[1] = thewin->work.g_y;
  268.         pxyc[3] = thewin->work.g_y + gl_hchar;
  269.  /* set the clip rect to the line to be redrawn */ 
  270.         vs_clip(thewin->graf.handle,1,pxyc);
  271.         vr_recfl(thewin->graf.handle,pxyc);
  272.         graf_mouse(M_OFF, 0L);
  273.         one_line2(thewin,thewin->topchar); 
  274.         graf_mouse(M_ON, 0L);
  275.     }
  276. }
  277.